package station

import (
	"fmt"
	"github.com/Unixeno/TheMoon/planet/config"
	"github.com/Unixeno/TheMoon/planet/station/server/tcpserver"
	"time"
)

func GetServer() (Server, error) {
	cfg := config.SysConfig
	var server Server
	switch cfg.Station.ClientType {
	case "tcp":
		serverConfig := tcpserver.ServerConfig{
			Addr:           cfg.Station.Server,
			ReadDeadline:   time.Duration(cfg.Station.ReadDeadline) * time.Second,
			WriteDeadline:  time.Duration(cfg.Station.WriteDeadline) * time.Second,
			CAFile:         cfg.Station.CAFile,
			CertFile:       cfg.Station.CertFile,
			PrivateKeyFile: cfg.Station.PrivateKeyFile,
			VerifyClient:   cfg.Station.VerifyClient,
		}
		server = tcpserver.CreateServer(&serverConfig)
		break
	default:
		return nil, fmt.Errorf("unsupported server type")
	}
	return server, server.Init()
}
